﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.IO;
using System.Web;
using System.Web.UI.WebControls;
using JumbotCms.Common;
namespace JumbotCms.WebFile.Admin
{
    public partial class _masteradd : JumbotCms.API.AdminCenter
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Admin_Load("0000", "html");
            id = Str2Str(q("id"));
            Jumbot.DataOper.WebFormHandler wh = new Jumbot.DataOper.WebFormHandler(doh, "jcms_normal_user", btnSave);
            wh.AddBind(lblUserName, "UserName", true);
            wh.AddBind(txtAdminName, "AdminName", true);
            wh.AddBind(rbtnAdminState, "SelectedValue", "AdminState", false);
            this.txtAdminName.ReadOnly = false;
            wh.ConditionExpress = "id=" + id;
            wh.Mode = Jumbot.DataOper.OperationType.Modify;
            wh.validator = chkForm;
            wh.ModifyOk += new EventHandler(save_ok);
        }
        protected void bind_ok(object sender, EventArgs e)
        {
        }
        protected bool chkForm()
        {
            if (!CheckFormUrl())
                return false;
            if (!Page.IsValid)
                return false;
            doh.Reset();
            if (this.txtAdminPass1.Text.ToString() == "")
            {
                FinalMessage("请填写密码", "", 1);
                return false;
            }
            doh.SqlCmd = "SELECT AdminId FROM [jcms_normal_user] WHERE [AdminName]='" + txtAdminName.Text + "'";
            if (doh.GetDataTable().Rows.Count > 0)
            {
                FinalMessage("用户名重复", "", 1);
                return false;
            }
            return true;
        }
        protected void save_ok(object sender, EventArgs e)
        {
            doh.Reset();
            doh.ConditionExpress = "id=" + id;
            if (this.txtAdminPass1.Text != "")
                doh.AddFieldItem("AdminPass", GetHash32(this.txtAdminPass1.Text));
            doh.AddFieldItem("Setting", ",,");
            doh.AddFieldItem("Group", site.AdminGroupId);
            doh.AddFieldItem("AdminId", id);
            doh.Update("jcms_normal_user");
            FinalMessage("成功保存", site.Dir + "admin/close.htm", 0);
        }
    }
}
